#include <bits/stdc++.h>
using namespace std;
int cha[1000005];
int a[1000005];
// This code is used to calculate the number of times each index in the range
// [1, 1000000] is incremented
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    cha[l]++;
    cha[r + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + cha[i];
  }
  cout << *min_element(a + 1, a + n + 1) << endl;
  return 0;
}